package org.doubango.jni;

public class Libyuv {

    static {
        System.loadLibrary("yuv");
    }

    public native static void YV12ToI420(byte[] yv12Bytes, byte[] i420Bytes, int width, int height);

    public static void YV12ToNV12(byte[] yv12Bytes, byte[] nv12Bytes, int width, int height) {
        I420ToNV21(yv12Bytes, nv12Bytes, width, height);
    }

    public static native void NV21ToI420(byte[] nv21Bytes, byte[] i420Bytes, int width, int height);

    public static native void I420Rotate(byte[] srcI420Bytes, byte[] destI420Bytes, int width, int height, int degree);

    public static native void I420ToNV12(byte[] i420Bytes, byte[] nv12Bytes, int width, int height);

    /** I420转NV21，也可用于YV12转NV12，因为YV12中的UV和I420中的UV顺序正好相反，而NV12中的UV和NV21中的UV也正好相反，所以转换的操作是一样的 */
    public static native void I420ToNV21(byte[] i420Bytes, byte[] nv21Bytes, int width, int height);

    public static native void YV12ToNV12Rotate180(byte[] yv12Bytes, byte[] nv12Bytes, int width, int height);
    public static native void YV12ToNV12Rotate270Or90(byte[] yv12Bytes, byte[] nv12Bytes, int width, int height, boolean is270);

    public static native void NV21ToNV12(byte[] nv21Bytes, byte[] nv12Bytes, int width, int height);

    /** NV21转NV12，比上面的NV21ToNV12效率要高一点，此方法实现是直接修改原数组，而上面的NV21ToNV12方法是把转换后的数据放到新数组中 */
    public static native void NV21ToNV12Inplace(byte[] nv21Bytes, byte[] uv12Bytes, int width, int height);

}
